﻿using System;

/*
 * 日志操作帮助类
 * 2010年12月28日
 * William
 */

namespace Utility
{
    public class LogHelper
    {
        public static LogHelper Instance = new LogHelper();

        private LogHelper() { }

        private string LogPath = AppDomain.CurrentDomain.BaseDirectory;

        public void WriteEventLog(string LogStr, LogTypeEnum LogType)
        {
            try
            {
                string path = LogPath;
                switch (LogType)
                {
                    case LogTypeEnum.ect:
                        path = path + "Log\\ect\\";
                        break;
                    case LogTypeEnum.system:
                        path = path + "Log\\system\\";
                        break;
                    case LogTypeEnum.systemSuccess:
                        path = path + "Log\\system\\Success\\";
                        break;
                    case LogTypeEnum.unknow:
                        path = path + "Log\\unknow\\";
                        break;
                    case LogTypeEnum.sql:
                        path = path + "Log\\sql\\";
                        break;
                    case LogTypeEnum.sqlBusinessLogic:
                        path = path + "Log\\sql\\BusinessLogic\\";
                        break;
                    case LogTypeEnum.sqlDataAccess:
                        path = path + "Log\\sql\\DataAccess\\";
                        break;
                    case LogTypeEnum.sqlHandler:
                        path = path + "Log\\sql\\Handler\\";
                        break;
                    case LogTypeEnum.cache:
                        path = path + "Log\\Cache\\";
                        break;
                }
                string log = "";
                string fileName = DateTime.Now.ToString("yyyy-MM-dd") + ".log";

                DateTime dt = DateTime.Now;
                log = log + "[" + dt.ToString("yyyy-MM-dd HH:mm:ss:") + dt.Millisecond.ToString() + "]\t" + LogStr;
                log = log + "\r\n";

                FileHelper.Instance.SaveFile(path, fileName, log);
            }
            catch (Exception)
            {
            }
        }
    }

    public enum LogTypeEnum
    {
        ect = 0,
        system = 1,
        unknow = 2,
        sql = 3,
        sqlBusinessLogic = 4,
        sqlDataAccess = 5,
        sqlHandler = 6,
        systemSuccess = 7,
        cache= 8
    }
}